package com.nullpointer.idlegame.service;

import com.nullpointer.idlegame.service.properties.action.NeedCalculate;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

// 帧处理器
public class TickProcessor {

    // 静态实例变量，初始化为 null
    private static TickProcessor instance = null;

    private final List<NeedCalculate> needCalculateVals = new ArrayList<>();

    private ScheduledExecutorService tickOperationExecutors = null;

    private TickProcessor() {
    }

    private void loadAllVals () {
        this.needCalculateVals.add(null);
    }

    public synchronized static TickProcessor init() {
        if (instance != null) {
            return instance;
        }

        instance = new TickProcessor();

        instance.loadAllVals();

        instance.tickOperationExecutors = Executors.newSingleThreadScheduledExecutor();
        instance.tickOperationExecutors.scheduleAtFixedRate(() -> {
            System.out.println("TickProcessor started");
            System.out.println(instance.needCalculateVals.size());
        }, 1000, 1000, TimeUnit.MILLISECONDS);

        return instance;
    }
}
